package com.fyzk.utils;

/**
 * 重复点击检测相关工具类
 */

public class CheckClickUtils {

    private static long lastClickTime = 0;
    private static long last5ClickTime = 0;

    private static long lastClickTimeIn5 = 0;
    private static int clickTimes = 0;

    public synchronized static boolean isFastClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            lastClickTime = time;
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public synchronized static boolean isFastClick300() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 300) {
            lastClickTime = time;
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public synchronized static boolean is2sFastClick() {
        long time = System.currentTimeMillis();
        if (time - last5ClickTime < 2000) {
            last5ClickTime = time;
            return true;
        }
        last5ClickTime = time;
        return false;
    }

    public synchronized static boolean isFastClick5Times() {
        long time = System.currentTimeMillis();
        if (time - lastClickTimeIn5 < 500) {
            lastClickTimeIn5 = time;
            clickTimes++;
            if (clickTimes == 5) {
                clickTimes = 0;
                lastClickTimeIn5 = 0;
                return true;
            }
        } else {
            lastClickTimeIn5 = time;
            clickTimes = 1;
        }
        return false;
    }

}
